﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WorkItemAnalyser.Core.Assertions;
using WorkItemAnalyser.Core.Parsers;

namespace WorkItemAnalyser.Test.ParserTests
{
    [TestClass]
    public class TextLinkAssertionParserTests
    {
        [TestMethod]
        public void TextLinkAssertionParser_ParseAssertion_ShouldReturnNullForEmptyString()
        {
            //Arrange
            var textlinkAssertionParser = new TextLinkAssertionParser();

            //Act
            var assertion = textlinkAssertionParser.ParseAssertion("");

            //Assert
            Assert.IsNull(assertion);
        }

        [TestMethod]
        public void TextLinkAssertionParser_ParseAssertion_ShouldReturnNullForNonConformingString()
        {
            //Arrange
            var textlinkAssertionParser = new TextLinkAssertionParser();

            //Act
            var assertion = textlinkAssertionParser.ParseAssertion("an incorrectly formatted string");

            //Assert
            Assert.IsNull(assertion);
        }

        [TestMethod]
        public void TextLinkAssertionParser_ParseAssertion_ShouldReturnAssertionForValidString()
        {
            //Arrange
            var textlinkAssertionParser = new TextLinkAssertionParser();

            //Act
            var assertion = textlinkAssertionParser.ParseAssertion("must have 2 child links to a task");

            //Assert
            Assert.IsNotNull(assertion);
        }

        [TestMethod]
        public void TextLinkAssertionParser_ParseAssertion_ShouldReturnAssertionWithCorrectCount()
        {
            //Arrange
            var textlinkAssertionParser = new TextLinkAssertionParser();
            
            //Act
            var assertion = (LinkAssertion)textlinkAssertionParser.ParseAssertion("must have 2 child links to a task");

            //Assert
            Assert.IsNotNull(assertion);
            Assert.IsTrue(assertion.Count == 2);
        }

        [TestMethod]
        public void TextLinkAssertionParser_ParseAssertion_ShouldReturnAssertionWithCorrectLinkType()
        {
            //Arrange
            var textlinkAssertionParser = new TextLinkAssertionParser();
            
            //Act
            var assertion = (LinkAssertion)textlinkAssertionParser.ParseAssertion("must have 2 child links to a task");
        
            //Assert
            Assert.IsNotNull(assertion);
            Assert.AreEqual("child", assertion.LinkType, true);
        }


        [TestMethod]
        public void TextLinkAssertionParser_ParseAssertion_ShouldReturnAssertionWithCorrectWorkItemType()
        {
            //Arrange
            var textlinkAssertionParser = new TextLinkAssertionParser();
            
            //Act
            var assertion = (LinkAssertion)textlinkAssertionParser.ParseAssertion("must have 2 child links to a task");
            
            //Assert
            Assert.IsNotNull(assertion);
            Assert.AreEqual("task", assertion.WorkItemType, true);
        }

        [TestMethod]
        public void TextLinkAssertionParser_ParseAssertion_ShouldReturnAssertionWithCorrectMultiWordWorkItemType()
        {
            //Arrange
            var textlinkAssertionParser = new TextLinkAssertionParser();
            
            //Act
            var assertion = (LinkAssertion)textlinkAssertionParser.ParseAssertion("must have 2 child links to a sprint backlog item");
            
            //Assert
            Assert.IsNotNull(assertion);
            Assert.AreEqual("sprint backlog item", assertion.WorkItemType, true);
        }
       
        [TestMethod]
        public void TextLinkAssertionParser_ParseAssertion_ShouldReturnAssertionForLooseMatchSyntax()
        {
            //Arrange
            var textlinkAssertionParser = new TextLinkAssertionParser();
            
            //Act
            var assertion = (LinkAssertion)textlinkAssertionParser.ParseAssertion("must have at least 1 child link to a sprint backlog item");
            
            //Assert
            Assert.IsNotNull(assertion);
        }
    }
}
